package com.vend.common.base
import android.util.Log
import com.just.agentweb.MiddlewareWebClientBase
import com.vend.common.base.sonic.SonicImpl
import com.vend.common.mvp.IPresenter
/**
 * Created by glendal on 2022/01/18.
 * 支持秒开url
 */
abstract class BaseWebOpenFastFragment<T : IPresenter> : BaseWebFragment<T>() {
    private var mSonicImpl: SonicImpl? = null
    override fun lazyInit() {
        Log.e("tag","lazyInit")
        // 1. 首先创建SonicImpl
        // 1. 首先创建SonicImpl
        mSonicImpl = SonicImpl(getSnoicUrl(), this.context)
        // 2. 调用 onCreateSession
        // 2. 调用 onCreateSession
        mSonicImpl?.onCreateSession()
        super.lazyInit()
        mSonicImpl?.bindAgentWeb(mAgentWeb)

    }


    override fun getMiddleWareWebClient(): MiddlewareWebClientBase {
        return mSonicImpl!!.createSonicClientMiddleWare()
    }
    //getUrl 应该为null
    override fun getUrl(): String? {
        return null
    }
    abstract fun getSnoicUrl() : String
    override fun onDestroyView() {
        super.onDestroyView()
        //销毁SonicSession
        if (mSonicImpl != null) {
            mSonicImpl!!.destrory()
        }
    }
}